package com.yn.pet.controller.app;


import com.yn.common.core.domain.AjaxResult;
import com.yn.pet.controller.app.biz.ASettingsBizService;
import com.yn.pet.controller.pc.request.AlarmUpdateRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@AllArgsConstructor
@RequestMapping("/front/more/settings")
@Api(tags = "app端——更多设置")
@Slf4j
public class AMoreSettingsController {
    private final ASettingsBizService moreSettingsBizService;


    /**
     * 一键重启
     * @param deviceId 设备id
     * @return
     */
    @PostMapping("reboot")
    @ApiOperation("一键重启")
    public AjaxResult reboot(@RequestParam @NotNull Long deviceId) {
        log.info("一键重启入参,deviceId:{}", deviceId);
        moreSettingsBizService.reboot(deviceId);
        return AjaxResult.success("设置成功");
    }

    /**
     * 获取设备报警信息
     * @param deviceId 设备ID
     * @return DeviceSyncSettings
     */
    @GetMapping("alarm/info")
    @ApiOperation("获取报警信息列表")
    public AjaxResult alarmInfo(@RequestParam @NotNull Long deviceId) {
        log.info("获取设备报警信息");
        return AjaxResult.success(moreSettingsBizService.getAlarmInfo(deviceId));
    }

    /**
     * 更新设备报警信息
     * @param request 报警信息
     * @return
     */
    @PostMapping("alarm/update")
    @ApiOperation("更新设备报警信息")
    public AjaxResult updateAlarm(@RequestBody @Validated AlarmUpdateRequest request) {
        log.info("更新设备报警信息入参，request:{}", request);
        moreSettingsBizService.updateAlarm(request);
        return AjaxResult.success("更新成功");
    }

    /**
     * 添加联系人
     * @param sign 1:呼入 2:呼出 3:呼入/呼出
     * @param phoneNumber 号码
     * @param name 姓名
     * @return null
     */
    @PostMapping("add/concat")
    @ApiOperation("添加联系人")
    public AjaxResult addConcat(@RequestParam @NotNull @ApiParam("1:呼入 2:呼出 3:呼入/呼出") Integer sign,
                                @RequestParam @NotNull @ApiParam("号码") String phoneNumber,
                                @RequestParam @NotNull @ApiParam("姓名") String name) {
        moreSettingsBizService.addConcat(sign, phoneNumber, name);
        return AjaxResult.success("添加成功");
    }
}
